<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\RoomConfig;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Controllers\AdminController;

class RoomConfigController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new RoomConfig(), function (Grid $grid) {
            $grid->id->sortable();
            $grid->area;
            $grid->price;
            $grid->cycle;
            $grid->cycle_unit;
            $grid->bet_count;
            $grid->pay_count;
            $grid->image;
            $grid->created_at;
            $grid->updated_at->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new RoomConfig(), function (Form $form) {
            $form->display('id');
            $form->decimal('area');
            $form->decimal('price');
            $form->select('cycle')->options(range(1, 30))->default(0);
            $form->select('cycle_unit')->options(['月', '年'])->default(0);
            $bet_count = array_map(function ($value) {
                return "押" . $value;
            }, range(1, 20));
            $form->select('bet_count')->options($bet_count)->default(0);
            $pay_count = array_map(function ($value) {
                return "付" . $value;
            }, range(1, 20));
            $form->select('pay_count')->options($pay_count)->default(0);
            $form->image('image');
        });
    }
}
